﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Trippy.Animation;
using Trippy.CollidableGameComponents.Agents;
using Trippy.Levels;

namespace Trippy.CollidableGameComponents.Objects
{
    class Orb : CollidableGameComponents.CollidableGameComponent
    {
        public static Texture2D SpriteSheet { get; private set; }

        protected int PointValue; //accessed via Value
        public int Value 
        {
            get
            {
                return PointValue;
            }
            set
            {
                //currently supports range of values from 1 to 3
                if (value < 1)
                    PointValue = 1;
                else if (value > 3)
                    PointValue = 3;
                else
                    PointValue = value;
            }
        }

        protected override void LoadContent()
        {
            if (SpriteSheet == null) SpriteSheet = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Objects/orb");
            Sprite = new AnimatedSprite(this, SpriteSheet, SpriteSheet.Height, SpriteSheet.Width, 0, 0, 0, 0, 1, 0f);
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            Sprite.Tint = ValueToColor(Value);
            StandardDraw(gameTime);
            base.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {
            UpdateStandardPhysics(TrippyUtilities.CalculateElapsedTime(gameTime));
            base.Update(gameTime);
        }

        public Orb(Level level)
            : base (level)
        {
        }


        private static Color ValueToColor(int v)
        {
            switch (v)
            {
                case 1:
                    return Color.Blue;
                case 2:
                    return Color.Red;
                case 3:
                    return Color.Gold;
                default:
                    return Color.White;
            }
        }


        protected override void CollisionHandler(CollidableGameComponent component, CollidableGameComponent.CollisionSide side)
        {
            if (component is Hero)
            {
                Hero h = (Hero) component;
                h.AddPoints(Value);
                MarkForDeletion();
            }
            base.CollisionHandler(component, side);
        }
    }
}
